package com.geeguo.ebuilder.client.business.system.logincertificate.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.geeguo.ebuilder.client.base.database.annotation.TDS;
import com.geeguo.ebuilder.client.base.tenant.model.DataContext;
import com.geeguo.ebuilder.client.business.system.logincertificate.mapper.LoginCertificateMapper;
import com.geeguo.ebuilder.client.business.system.logincertificate.model.LoginCertificateEntity;
import com.geeguo.ebuilder.client.business.system.logincertificate.service.LoginCertificateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class LoginCertificateServiceImpl extends ServiceImpl<LoginCertificateMapper, LoginCertificateEntity> implements LoginCertificateService {

    @Autowired
    private LoginCertificateMapper loginCertificateMapper;

    @TDS
    @Override
    public LoginCertificateEntity getByCertificate(String certificate, DataContext dataContext) {
        return loginCertificateMapper.getByCertificate(certificate, dataContext.getTenantCode());
    }

    @TDS
    @Override
    public boolean save(LoginCertificateEntity entity, DataContext dataContext) {
        return loginCertificateMapper.insert(entity) > 0;
    }

    @TDS
    @Override
    @Transactional
    public boolean batchSave(List<LoginCertificateEntity> list, DataContext dataContext) {
        return this.saveBatch(list);
    }

    @TDS
    @Override
    public boolean removeByUserId(String userId, DataContext dataContext) {
        return loginCertificateMapper.removeByUserId(userId) >= 0;
    }
}